using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Collections;

namespace Hack.DllDump
{   
    public class OneType
    {
        /*
         * See if we should disassemble the method source
         */
        protected bool _ShowCode = false;
        public bool ShowCode
        {
            get {   return _ShowCode; }
            set {   _ShowCode = value; }
        }

        public ArrayList PropertyList = new ArrayList();
        public ArrayList MemberList = new ArrayList();
        public ArrayList MethodList = new ArrayList();
        public ArrayList EventList = new ArrayList();
        public ArrayList ConstructorList = new ArrayList();
        public ArrayList InterfaceList = new ArrayList();

        string TypeName;
        string guid;

        public OneType(string TypeName, string guid)
        {
            this.TypeName = TypeName;
            this.guid = guid;
        }

        public void AddProperty(PropertyInfo info)
        {
            PropertyList.Add(new Property(info));
        }

        public void AddMember(MemberInfo info)
        {
            MemberList.Add(new Member(info));
        }

        public void AddMethod(MethodInfo info)
        {
            MethodList.Add(new Method(info));
        }

        public void AddEvent(EventInfo info)
        {
            EventList.Add(new Event(info));
        }

        public void AddConstructor(ConstructorInfo info)
        {
            ConstructorList.Add(new Constructor(info));
        }

        public void AddInterface(System.Type info)
        {
            InterfaceList.Add(new Interface(info));
        }

        public void ToString(StringWriter sw)
        {
            sw.WriteLine("Type: {0} ", this.TypeName);
            sw.WriteLine("Guid: {0} ", this.guid);
            /*
             * Display constructors
             */
            sw.WriteLine("Constructors ---------------");

            foreach (Constructor c in ConstructorList)
            {
                c.ToString(sw);
                sw.WriteLine("");
            }


            PropertyList.Sort();
            sw.WriteLine("Properties --------");
            foreach (Property p in PropertyList)
            {
                sw.WriteLine("");
                p.ToString(sw);
                sw.WriteLine("");

            }

            MethodList.Sort();
            sw.WriteLine("Methods  --------");
            foreach (Method m in MethodList)
            {
                sw.WriteLine("");
                m.ToString(sw,ShowCode);
                sw.WriteLine("");
            }


            EventList.Sort();
            sw.WriteLine("Events  --------");
            foreach (Event e in EventList)
            {
                e.ToString(sw);
                sw.WriteLine("");
            }

        }
    }

  
}
